#include "nicdialog.h"
#include "ui_nicdialog.h"
#include <QStandardItemModel>
NICDialog::NICDialog(pcap_if_t *devs,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::NICDialog)
{
ui->setupUi(this);
model= new QStandardItemModel(0,3,this);
model->setHeaderData(1,Qt::Horizontal,tr("id"));
model->setHeaderData(1,Qt::Horizontal,tr("description"));
model->setHeaderData(2,Qt::Horizontal,tr("name"));
ui->treeView->setModel(model);
ui->treeView->setRootIsDecorated(false);
ui->treeView->setAlternatingRowColors(true);
    pcap_if_t *c;
    int index_nic=0;
    for(c=devs;c;c=c->next)
    {
        index_nic++;
        QString s=QString("%1|%2").arg(c->description).trimmed().arg(c->name);
        model->insertRow(0);
        model->setData(model->index(0,0),index_nic);
        model->setData(model->index(0,1),c->description);
        model->setData(model->index(0,2),c->name);
        index_nic++;
    }
}

NICDialog::~NICDialog()
{

    delete ui;
}

void NICDialog::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}
void NICDialog::on_treeView_doubleClicked(QModelIndex index)
{
QString f=ui->textEdit->toPlainText();
int p=ui->checkBox->checkState()==Qt::Checked?1:0;
    emit setNIC(model->item(index.row(),2)->text(),f,p);
    this->accept();
}
